package com.boot2523.myredis.r2;

import com.boot2523.bean.Goods;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import redis.clients.jedis.Jedis;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class R4 {
    public static void main(String[] args) {
        //取出缓存中的热点商品
        Jedis j=new Jedis();
        if (j.hexists("hotgoods","mygoods")){
            Map<String,String> data=j.hgetAll("hotgoods");
            System.out.println(data);
            Goods data2[]=new Gson().fromJson(data.get("mygoods"),new TypeToken<Goods[]>(){}.getType());
            System.out.println(data2);
            //找出价格为2000的手机信息
            for (Goods g:data2) {
                if (g.getPrice()==2000) {
                    System.out.println(g);
                    break;
                }
            }
            //通过流操作
            System.out.println(Arrays.stream(data2).filter(g->g.getPrice()==2000).collect(Collectors.toList()));
        }else{
            System.out.println("热点商品不存在");
        }
    }
}
